package com.itheima.jobs;

import com.itheima.constant.RedisConstant;
import com.itheima.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/**
 * 代码使我快乐 Administrator on 2019/12/4.
 */
public class ClearImgJob {
    @Autowired
    private JedisPool jedisPool;

    public void clearImg(){

//        根据redis中的两个set集合的差值删除垃圾图片
        Set<String> set = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if (set != null){
            for (String name : set) {
                QiniuUtils.deleteFileFromQiniu(name);
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES, name);
                System.out.println("清理图片"+name);
            }
        }

    }
}
